﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Money
{
    // TODO we should refactor this so that we always have a shotcut and object that it works on, need new base class etc.

    [Serializable]
    public class CategoriseShortcut
    {
        public KeyboardShortcut ShortCut { get; set; }
        
        public int? CategoryId { get; set; }

        public Transaction.TransactionType? Type { get; set; }

        public string Comment { get; set; }
        public string Description { get; set; }

        public string MenuOption { get; set; }

        public CategoriseShortcut()
        {
            ShortCut = new KeyboardShortcut();
        }

        public bool Equals(CategoriseShortcut shortcut)
        {
            // TODO we should refactor for single exit point now that it has grown
            if (shortcut == null)
            {
                return false;
            }

            if (shortcut == this)
            {
                return true;
            }

            if ((string.IsNullOrEmpty(Comment) != string.IsNullOrEmpty(shortcut.Comment)))
            {
                return false;
            }
            else if (!string.IsNullOrEmpty(Comment) && (!Comment.Equals(shortcut.Comment)))
            {
                return false;
            }

            if (CategoryId == null && shortcut.CategoryId != null)
            {
                return false;
            }
            else if (shortcut.CategoryId == null && CategoryId != null)
            {
                return false;
            }
            else if (CategoryId != shortcut.CategoryId)
            {
                return false;
            }

            if (ShortCut.Equals(shortcut.ShortCut) 
                && CategoryId == shortcut.CategoryId 
                && Type == shortcut.Type 
                && ((string.IsNullOrWhiteSpace(Comment) == string.IsNullOrWhiteSpace(shortcut.Comment))  || (Comment.Equals(shortcut.Comment))))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
